package com.ln.prac.base.xiaoao.dataStructure;

import java.util.Stack;

/**
 * 使用两个栈实现的队列
 *
 * @Author zhangj
 * @Date 2023/2/6 21:37
 */
public class MyDoubleStackQueue<T> {

    Stack<T> s1 = new Stack<>();
    Stack<T> s2 = new Stack<>();

    public void enqueue(T e) {
        s1.push(e);
    }

    public T dequeue() {
        if (s2.size() > 0) {
            return s2.pop();
        }
        while (s1.size() > 0) {
            s2.push(s1.pop());
        }
        return s2.pop();
    }

    public int size() {
        return s1.size() + s2.size();
    }

}
